package com.arsn.myf.generate.controller;

import com.arsn.myf.common.util.result.Func;
import com.arsn.myf.common.util.result.R;
import com.arsn.myf.generate.entity.TableColumnInfo;
import com.arsn.myf.generate.service.TableColumnInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wildfly.common.annotation.NotNull;
import java.util.Arrays;

/**
 * 表列信息
 * @author zhongrj
 * @since 2022-12-07
 */
@RestController
@RequestMapping("/tableColumnInfo")
@AllArgsConstructor
@Api(value = "表列信息", tags = "表列信息")
public class TableColumnInfoController {

    private final TableColumnInfoService tableColumnInfoService;


    /**
     * 查询表列信息的分页数据
     * @param page
     * @param tableColumnInfoTable
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询表列信息的分页数据")
    public R list(Page<TableColumnInfo> page, TableColumnInfo tableColumnInfoTable){
        return R.data(tableColumnInfoService.page(page,new QueryWrapper<>(tableColumnInfoTable)));
    }


    /**
     * 表列信息详情信息
     * @param tableColumnInfoTable
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "表列信息详情信息")
    public R detail(TableColumnInfo tableColumnInfoTable){
        return R.data(tableColumnInfoService.getOne(new QueryWrapper<>(tableColumnInfoTable)));
    }


    /**
     * 表列信息新增
     * @param tableColumnInfoTable
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "表列信息新增")
    public R save(@RequestBody TableColumnInfo tableColumnInfoTable){
        return R.status(tableColumnInfoService.save(tableColumnInfoTable));
    }

    /**
     * 表列信息修改
     * @param tableColumnInfoTable
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "表列信息修改")
    public R update(@RequestBody TableColumnInfo tableColumnInfoTable){
        return R.status(tableColumnInfoService.updateById(tableColumnInfoTable));
    }

    /**
     * 删除,批量删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ApiOperation(value = "删除,批量删除")
    public R remove(@NotNull String ids){
        return R.status(tableColumnInfoService.removeByIds(Func.stringToLong(Arrays.asList(ids.split(",")))));
    }

}
